package info.heidao.ww2.api.interceptor;

import com.github.lianjiatech.retrofit.spring.boot.interceptor.BasePathMatchInterceptor;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @author: zhengheng
 * @Date: 2021-08-03 15:20
 * @Description:
 */
@Slf4j
@Component
public class CookieInterceptor extends BasePathMatchInterceptor {

    private static final Map<String, String> headers = Maps.newHashMap();

    static {
        headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        headers.put("Accept-Encoding", "gzip, deflate, br");
        headers.put("Accept-Language", "max-age=0");
        headers.put("Connection", "keep-alive");
        headers.put("Cookie", "session-api=hi9hqrdlkuanmudsiobnrabine");
        headers.put("Host", "www.bigfun.cn");
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36");
    }

    @Override
    protected Response doIntercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        headers.forEach(builder::header);
        return chain.proceed(builder.build());
    }
}
